package org.pblue.appengine.data.control;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.pblue.appengine.data.caching.Cache;


public class InvalidateCachesServlet extends HttpServlet {
  
  public static final String CALLBACK_PARAMETER = "callback";

  private static final long serialVersionUID = 1L;

  @Override
  protected void service(HttpServletRequest pReq, HttpServletResponse pRes) throws ServletException, IOException {
    String callback = pReq.getParameter(CALLBACK_PARAMETER);
    
    Cache.cache().clear();
    pRes.getWriter().println("Caches invalidated");
    
    if (callback != null && !callback.equals("")) {
      pRes.sendRedirect(callback);
    }
  }

}
